using System;
using System.Collections;
using System.Data;
using PCSComUtils.PCSExc;
using PCSComProduction.WorkOrder.DS;
using PCSComProduction.ShopFloorControl.DS;
using PCSComProduction.ScrapRecording.DS;

namespace PCSComProduction.ShopFloorControl.BO
{
	public class DispatchListByWorkCenterBO //:  IDispatchListByWorkCenterBO
	{
		public DispatchListByWorkCenterBO()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		//[AutoComplete(true)]
		public DataSet SearchDispatchDetail(Hashtable phashCondition)
		{
			try
			{
				PRO_DispatchDetailDS dsPRO_DispatchDetailDS = new PRO_DispatchDetailDS();
				return dsPRO_DispatchDetailDS.SearchDispatchDetail(phashCondition);
			}
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
		}
		/// <summary>
		/// Call PRO_OperationStatusDS.List and return DataTable
		/// </summary>
		//[AutoComplete(true)]
		public DataTable GetOperationStatus()
		{
			try
			{
				PRO_OperationStatusDS dsOperationStatus = new PRO_OperationStatusDS();
				return dsOperationStatus.List().Tables[0];
			}
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		

		//[AutoComplete(true)]
		public decimal GetPerviousWORoutingStepQty(int pintWOLineID, int pintWORoutingID, int pintStep, decimal pdcmCurrentCompletedQty)
		{
			try
			{
				PRO_WORoutingDS dsPRO_WORoutingDS = new PRO_WORoutingDS();
				int intPreviousRoutingID = dsPRO_WORoutingDS.GetRoutingIDOfPreviousStep(pintWOLineID,pintStep);

				if (intPreviousRoutingID == 0)
				{
					//there is just only one routing
					//and there is no pervious routing step to this step
					return pdcmCurrentCompletedQty;
				}

				//get the completed quantity for this step
				PRO_DispatchDetailDS dsPRO_DispatchDetailDS = new PRO_DispatchDetailDS();
				return dsPRO_DispatchDetailDS.GetCompletedQty(pintWOLineID, intPreviousRoutingID);
				
			}			
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}

		}

		/// <summary>
		/// This method is used to check the Previous operation is finished or not
		/// If this is the first operation ==> we will return true
		/// otherwise we need to check the Received Person ID
		/// if this field is null ==> it means that this operation is not finished
		/// </summary>
		/// <param name="pintWODetailID"></param>
		/// <param name="pintWORoutingID"></param>
		/// <param name="pintStep"></param>
		/// <returns></returns>
		//[AutoComplete(true)]
		public bool CheckIfPreviousOperationIsFinished(int pintWODetailID, int pintWORoutingID, int pintStep)
		{
			try
			{
				//first we need to get the previous operation id

				PRO_WORoutingDS dsPRO_WORoutingDS = new PRO_WORoutingDS();
				int intPreviousRoutingID = dsPRO_WORoutingDS.GetRoutingIDOfPreviousStep(pintWODetailID,pintStep);

				if (intPreviousRoutingID == 0)
				{
					//there is just only one routing
					//and there is no pervious routing step to this step
					return true;
				}

				//now we have the previous routing
				//we need to get the received person id
				PRO_DispatchDetailDS dsPRO_DispatchDetailDS = new PRO_DispatchDetailDS();
				int intReceivedPersonID = dsPRO_DispatchDetailDS.GetReceivedPersonID(pintWODetailID, intPreviousRoutingID);
				if (intReceivedPersonID > 0)
				{
					return true;
				}
				else
				{
					return false;
				}
			}			
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}

		}
		#region IObjectBO Members

		/// <summary>
		/// Update the DataSet back to database
		/// </summary>
		/// <param name="dstData"></param>
		//[AutoComplete(true)]
		public void UpdateDataSet(DataSet dstData)
		{
			try
			{
				PRO_DispatchDetailDS dsPRO_DispatchDetailDS = new PRO_DispatchDetailDS();
				dsPRO_DispatchDetailDS.UpdateDataSet(dstData);
			}			
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}

		}

		public void Update(object pObjectDetail)
		{
			// TODO:  Add DispatchListByWorkCenterBO.Update implementation
		}

		public void Delete(object pObjectVO)
		{
			// TODO:  Add DispatchListByWorkCenterBO.Delete implementation
		}

		public void Add(object pObjectDetail)
		{
			// TODO:  Add DispatchListByWorkCenterBO.Add implementation
		}

		public object GetObjectVO(int pintID, string VOclass)
		{
			// TODO:  Add DispatchListByWorkCenterBO.GetObjectVO implementation
			return null;
		}

		#endregion
	}
}
